package cn.cqie.frame.controller;

import cn.cqie.frame.bo.add.AddMenuBo;
import cn.cqie.frame.bo.query.QueryMenuBo;
import cn.cqie.frame.service.SysMenuService;
import cn.cqie.frame.vo.*;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;
import java.util.List;

/**
 * <p>
 *  前端控制器
 * </p>
 * @author XYHL
 * @since 2021-09-14
 */
@RestController
@Api("菜单管理")
public class SysMenuController {
    @Autowired
    private SysMenuService sysMenuService;

    /**
     * 查询菜单信息
     * @param bo
     * @return
     */
    @ApiOperation("查询菜单信息")
    @GetMapping(value = "/menus/queryMenu")
    public ResultVo<List<MenuVo>> queryMenu( QueryMenuBo bo) {
        List<MenuVo> menuVoList = sysMenuService.queryMenu(bo);
        return ResultVo.success(menuVoList);
    }

    /**
     * 新增菜单信息
     * @param bo
     * @return
     */
    @ApiOperation("新增菜单信息")
    @PostMapping(value = "/menus/saveOrUpdateMenu")
    public ResultVo<MenuVo> saveOrUpdateMenu(@Valid @RequestBody AddMenuBo bo) {
        MenuVo menuVo = sysMenuService.saveOrUpdateMenu(bo);
        return ResultVo.success(menuVo);
    }

    /**
     * 查看角色菜单选项
     * @return labelOptionVos
     */
    @ApiOperation(value = "查看角色菜单选项")
    @GetMapping("/menus/role")
    public ResultVo<List<LabelOptionVo>> listMenuOptions() {
        List<LabelOptionVo> labelOptionVos = sysMenuService.listMenuOptions();
        return ResultVo.success(labelOptionVos);
    }

    /**
     * 查询当前用户的菜单信息
     * @return
     */
    @ApiOperation("查询当前用户的菜单信息")
    @GetMapping(value = "/menus/userMenuList")
    public ResultVo<List<UserMenuVo>> userMenuList() {
        return ResultVo.success(sysMenuService.userMenusList());
    }

    /**
     * 删除菜单信息
     * @param MenuId
     * @return
     */
    @ApiOperation("删除菜单信息")
    @DeleteMapping("/menus/deleteMenu/{MenuId}")
    public ResultVo<Void> deleteMenu(@PathVariable Long MenuId) {
        Boolean delete = sysMenuService.deleteMenu(MenuId);
        return delete ? ResultVo.success() : ResultVo.error("删除失败");
    }
}

